package ui

import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods
import dominio.Jugador
import org.apache.wicket.markup.html.WebPage
import applicationModel.JardinZen
import org.uqbar.wicket.xtend.XListView
import org.apache.wicket.markup.html.basic.Label
import org.apache.wicket.model.PropertyModel
import org.uqbar.wicket.xtend.XButton
import org.apache.wicket.markup.html.form.Form
import org.apache.wicket.model.IModel
import dominio.Planta
import org.apache.wicket.model.CompoundPropertyModel
import org.apache.wicket.markup.html.form.TextField

class JardinZenTerrestrePage extends WebPage{
	
	
	extension WicketExtensionFactoryMethods = new WicketExtensionFactoryMethods
	public Jugador jugador;
	public JardinZen jardinZen;
	public JardinTableroPage mainPage
	
	new(Jugador jugadorX, JardinTableroPage mainPageX){
		
		jugador = jugadorX;
		mainPage = mainPageX
		
		
		this.main();	
	}
	
	def main() {
		
		this.setearJardinZen();
		val listView = new XListView<Planta>("plantas", new PropertyModel(jardinZen, "plantas"))
		listView.populateItem = [ item |
			item.model = item.modelObject.asCompoundModel
			item.addChild(new Label("nombre"))
			item.addChild(new Label("puntosDanio"))
			item.addChild(new Label("capacidadDefensiva"))
								]
								
		this.addChild(listView)	
		this.botones()
		}
	
	def botones() {
		val Form<String> form = new Form<String>("form");
		form.addChild(new XButton("volver").onClick = [|this.volverATablero()]);
		form.addChild(new XButton("cambiarJardin").onClick = [|this.switchJardin()]);
		this.addChild(form)
	}
	
	def volverATablero() {
		responsePage = mainPage
	}
	
	def switchJardin() {
		responsePage = new JardinZenAcuaticoPage(jugador, mainPage, this)
	}
	
	def setearJardinZen() {
		jardinZen = jugador.getJterrestre
		}
		

	}